package cn.fastoo.common.utils;

import cn.fastoo.common.cache.Price;
import cn.fastoo.common.cache.PriceCache;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Map;

public class PriceUtil {

    public static Price load(JdbcTemplate jdbcTemplate, String apiKey, String countryCode) {
            PriceCache pc = new PriceCache(jdbcTemplate, apiKey, 1200); //20minute
        Map<String, Price> priceMap = (Map) pc.get();

        if (priceMap.containsKey(countryCode)) {
            return priceMap.get(countryCode);
        } else {
            Price price = new Price();

            price.setCountryCode("00");
            price.setMtPrice(0.3);
            price.setVtPrice(0.5);

            return price;
        }
    }
}
